package test.sgone.cn.mulimagedemo;

import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import java.lang.reflect.Array;
import java.util.ArrayList;

/**
 * Created by stone_fan on 2016/7/14.
 */
public class MyPagerAdapter extends PagerAdapter {
    private ArrayList<View> listVies;
    private int size;

    public MyPagerAdapter(ArrayList<View> listViews)
    {
        this.listVies=listViews;
        size = listViews==null?0:listViews.size();
    }

    public void setListViews(ArrayList<View> listViews) {// 自己写的一个方法用来添加数据
        this.listVies = listViews;
        size = listViews == null ? 0 : listViews.size();
    }

    @Override
    public int getCount() {
        return size;
    }

    @Override
    public int getItemPosition(Object object) {
        return POSITION_NONE;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        ((ViewPager)container).removeView(listVies.get(position%size));
    }

    @Override
    public void finishUpdate(ViewGroup container) {
        super.finishUpdate(container);
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        try{
            ((ViewPager)container).addView(listVies.get(position%size),0);
        }catch (Exception e)
        {

        }
        return listVies.get(position%size);


    }


    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }
}
